package com.ruoyi.performance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.performance.domain.TPerformanceTemplate;
import com.ruoyi.performance.service.ITPerformanceTemplateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 考核模板Controller
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@RestController
@RequestMapping("/performanceTemplate")
public class TPerformanceTemplateController extends BaseController
{
    @Autowired
    private ITPerformanceTemplateService tPerformanceTemplateService;

    /**
     * 查询考核模板列表
     */
    @RequiresPermissions("performance:performanceTemplate:list")
    @GetMapping("/list")
    public TableDataInfo list(TPerformanceTemplate tPerformanceTemplate)
    {
        startPage();
        List<TPerformanceTemplate> list = tPerformanceTemplateService.selectTPerformanceTemplateList(tPerformanceTemplate);
        return getDataTable(list);
    }

    /**
     * 导出考核模板列表
     */
    @RequiresPermissions("performance:performanceTemplate:export")
    @Log(title = "考核模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPerformanceTemplate tPerformanceTemplate)
    {
        List<TPerformanceTemplate> list = tPerformanceTemplateService.selectTPerformanceTemplateList(tPerformanceTemplate);
        ExcelUtil<TPerformanceTemplate> util = new ExcelUtil<TPerformanceTemplate>(TPerformanceTemplate.class);
        util.exportExcel(response, list, "考核模板数据");
    }

    /**
     * 获取考核模板详细信息
     */
    @RequiresPermissions("performance:performanceTemplate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPerformanceTemplateService.selectTPerformanceTemplateById(id));
    }

    /**
     * 新增考核模板
     */
    @RequiresPermissions("performance:performanceTemplate:add")
    @Log(title = "考核模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPerformanceTemplate tPerformanceTemplate)
    {
        return toAjax(tPerformanceTemplateService.insertTPerformanceTemplate(tPerformanceTemplate));
    }

    /**
     * 修改考核模板
     */
    @RequiresPermissions("performance:performanceTemplate:edit")
    @Log(title = "考核模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPerformanceTemplate tPerformanceTemplate)
    {
        return toAjax(tPerformanceTemplateService.updateTPerformanceTemplate(tPerformanceTemplate));
    }

    /**
     * 删除考核模板
     */
    @RequiresPermissions("performance:performanceTemplate:remove")
    @Log(title = "考核模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPerformanceTemplateService.deleteTPerformanceTemplateByIds(ids));
    }

    /**
     * 根据老师类型查询工作名
     * @param teacherType
     * @return
     */
    @RequiresPermissions("performance:performanceTemplate:selectTeacherType")
    @GetMapping(value = "/selectTeacherType/{teacherType}")
    public List<String> selectProjectBytTeacherType(@PathVariable("teacherType") String teacherType)
    {
      List<String> projectList =  tPerformanceTemplateService.selectProjectBytTeacherType(teacherType);
        return projectList;
    }


}
